using Asteroid.Content;
using GameFramework.Extensions;
using GameFramework.GameObjects;
using Microsoft.Xna.Framework;

namespace Asteroid.GameObjects
{
    /// <summary>
    /// This class represent a bullet object.
    /// </summary>
    public class Bullet : Texture
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Bullet"/> class.
        /// </summary>
        public Bullet()
        {
            TextureName = Textures.Bullet;
        }

        /// <summary>
        /// Gets or sets the bullet speed.
        /// </summary>
        public Vector2 Speed { get; set; }

        /// <summary>
        /// Update the bullet.
        /// </summary>
        public override void Update()
        {
            base.Update();

            Position += Speed * (float)GameTime.ElapsedGameTime.TotalSeconds;
        }

        /// <summary>
        /// Initialize the bullet from the stream.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public override void Read(System.IO.BinaryReader reader)
        {
            base.Read(reader);

            Speed = reader.ReadVector2();
        }

        /// <summary>
        /// Save the bullet into the stream. 
        /// </summary>
        /// <param name="writer">The writer.</param>
        public override void Write(System.IO.BinaryWriter writer)
        {
            base.Write(writer);

            writer.WriteVector2(Speed);
        }
    }
}
